package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import pojo.Info;
import util.MyUtil;

@Component
@Aspect
public class DigestAspect {
	private final String p1="execution(* service.InfoManager.regist(..))";
	private final String p2="execution(* service.InfoManager.login(..))";
	
	@Around(value=p1)
	public Object regist(ProceedingJoinPoint point){
		Object object = null;
		Info info = (Info)point.getArgs()[0];
		String pwd = MyUtil.Encry(info.getPwd(),"md5");
		info.setPwd(pwd);
		try {
			object = point.proceed(new Object[]{info});
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return object;
	}
	
	@Around(value=p2)
	public Object login(ProceedingJoinPoint point){
		Object object = null;
		String s = (String)point.getArgs()[1];
		String pwd = MyUtil.Encry(s, "md5");
		try {
			object = point.proceed(new Object[]{point.getArgs()[0], pwd});
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return object;
	}

}
